// $Id: string_encoding.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#define XPCOM_SOURCE

#include <xpcom/config.hpp>
#include <xpcom/exception.hpp>
#include <xpcom/string_encoding.hpp>
#include "api/string.hpp"

namespace xpcom {

void string_encoding::ascii_to_utf16(const string& src, wstring& dest)
{
    ::NS_CStringToUTF16(
            src, NS_CSTRING_ENCODING_ASCII, dest) | throw_exception;
}

void string_encoding::native_to_utf16(const string& src, wstring& dest)
{
    ::NS_CStringToUTF16(
            src, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, dest) | throw_exception;
}

void string_encoding::utf8_to_utf16(const string& src, wstring& dest)
{
    ::NS_CStringToUTF16(
            src, NS_CSTRING_ENCODING_UTF8, dest) | throw_exception;
}

void string_encoding::utf16_to_ascii(const wstring& src, string& dest)
{
    ::NS_UTF16ToCString(
            src, NS_CSTRING_ENCODING_ASCII, dest) | throw_exception;
}

void string_encoding::utf16_to_native(const wstring& src, string& dest)
{
    ::NS_UTF16ToCString(
            src, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, dest) | throw_exception;
}

void string_encoding::utf16_to_utf8(const wstring& src, string& dest)
{
    ::NS_UTF16ToCString(
            src, NS_CSTRING_ENCODING_UTF8, dest) | throw_exception;
}

} // namespace xpcom
